package com.huzz.controller;

import com.huzz.entity.SysDict;
import com.huzz.model.SysDictCreateModel;
import com.huzz.model.SysDictQueryModel;
import com.huzz.model.SysDictUpdateModel;
import com.huzz.service.ISysDictService;
import com.huzz.util.body.JsonResult;
import com.huzz.util.body.ResultTool;
import com.huzz.util.log.Log;
import com.huzz.util.log.LogStarter;
import com.huzz.util.log.Operate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* 系统字典-业务模块
*
* @author 童年的纸飞机
* @since 2023-06-07 13:37
*/
@Slf4j
@LogStarter("系统字典模块")
@RestController
@RequestMapping("/api/SysDict")
@Api(value = "系统字典模块 API", tags = {"系统字典模块 API"})
public class SysDictController {

    @Autowired
    private ISysDictService sysDictService;

    @Log(name = "根据id查询系统字典", operateType = Operate.SELECT)
    @ApiOperation("根据id查询系统字典")
    @GetMapping("/findSysDictById")
    public JsonResult<SysDict> findSysDictById(@RequestParam Integer id) {
        return ResultTool.success(sysDictService.getSysDictById(id));
    }

    @Log(name = "新建系统字典", operateType = Operate.INSERT)
    @ApiOperation("新建系统字典")
    @PostMapping("/createSysDict")
    public JsonResult createSysDict(@Validated @RequestBody SysDictCreateModel model) {
        return sysDictService.createSysDict(model) ? ResultTool.success("新建成功") : ResultTool.fail("新建失败");
    }

    @Log(name = "更新系统字典", operateType = Operate.UPDATE)
    @ApiOperation("更新系统字典")
    @PutMapping("/updateSysDict")
    public JsonResult updateSysDict(@Validated @RequestBody SysDictUpdateModel model) {
        return sysDictService.updateSysDict(model) ? ResultTool.success("更新成功") : ResultTool.fail("更新失败");
    }

    @Log(name = "根据ID删除系统字典", operateType = Operate.DELETE)
    @ApiOperation("根据ID删除系统字典")
    @DeleteMapping("/removeSysDictById")
    public JsonResult removeSysDictById(@RequestParam Integer id) {
        return sysDictService.deleteSysDictById(id) ? ResultTool.success("删除成功") : ResultTool.fail("删除失败");
    }

    @Log(name = "分页查询系统字典", operateType = Operate.SELECT)
    @ApiOperation("分页查询系统字典列表")
    @GetMapping("/querySysDictPage")
    public JsonResult querySysDictPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    @Validated SysDictQueryModel model) {
        return ResultTool.success(sysDictService.selectSysDictPage(pageNum, pageSize, model));
    }

    @Log(name = "查询系统字典列表", operateType = Operate.SELECT)
    @ApiOperation("查询系统字典列表")
    @GetMapping("/querySysDictList")
    public JsonResult querySysDictList(@Validated SysDictQueryModel model) {
        return ResultTool.success(sysDictService.selectSysDictList(model));
    }

    @Log(name = "导出系统字典", operateType = Operate.EXPORT, saveResResult = false)
    @ApiOperation("导出系统字典列表")
    @GetMapping("/exportSysDictExcel")
    public void exportSysDictExcel(HttpServletRequest request, HttpServletResponse response, @Validated SysDictQueryModel model) {
        sysDictService.exportSysDictExcel(request, response, model);
    }

    @Log(name = "批量编辑系统字典", operateType = Operate.UPDATE)
    @ApiOperation("批量编辑系统字典")
    @PutMapping("/updateSysDictByList")
    public JsonResult updateSysDictByList(@RequestBody List<SysDictUpdateModel> modelList) {
        return ResultTool.response(sysDictService.updateSysDictByList(modelList));
    }

    @Log(name = "批量删除系统字典", operateType = Operate.DELETE)
    @ApiOperation("批量删除系统字典")
    @DeleteMapping("/removeSysDictByIds")
    public JsonResult removeSysDictByIds(@RequestBody List<Integer> ids) {
        return ResultTool.response(sysDictService.deleteSysDictByIds(ids));
    }

}




































